<include file="public@header"/>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="layui-input" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="layui-input" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('附件上传','#file-{id}','file');">替换</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="layui-fluid js-check-wrap">
    <div class="layui-card">
        <div class="layui-card-header">{:lang('PORTAL_ADMINLOSE_EDIT')}</div>

        <form action="{:url('AdminArticle/editPost')}" method="post" class="layui-form js-ajax-form" data-replace="1">
            <div class="layui-card-body">
                <div class="layui-tab">
                    <ul class="layui-tab-title">
                        <li class="layui-this">
                            <span class="icon-wrapper"><i class="fa fa-align-center"></i></span>
                            <span class="text-wrapper">{:lang('PORTAL_ADMINLOSE_EDIT')}</span>
                        </li>
                    </ul>

                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-card-body">
                                <!-- 标题 -->
                                <if condition="in_array('title',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('COMMON_TITLE')}</label>
                                    <div class="layui-input-block">
                                        <input type="hidden" name="post[id]" value="{$post.id}">
                                        <input class="layui-input form-replace" type="text" id="title" name="post[post_title]"
                                                value="{$post.post_title}"  data-field="article_title" placeholder="{:lang('PLEASE_ENTER')}{:lang('COMMON_TITLE')}"/>
                                    </div>
                                </div>
                                </if>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">分类</label>
                                    <div class="layui-input-block">
                                        <!-- 单选分类 -->
                                        <select class="layui-input" name="post[categories]">
                                            <option value=''>{:lang('SELECT_PLEASE')}{:lang('LOSE_CATEGORY')}</option>
                                            {$category_tree|default=''}
                                        </select>
                                    </div>
                                </div>

                                <!-- 领取地点 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">领取地点</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" id="receive_place" name="post[receive_place]"
                                               value="{$post['receive_place']}" data-field="receive_place" placeholder="请填写领取地点">
                                    </div>
                                </div>
                                
                                
                                <!-- 发布时间 -->
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('PUBLISHED_TIME')}</label>
                                
                                    <div class="layui-input-block">
                                        <div class="input-group">
                                            <input class="layui-input js-layui-datetime" type="text" name="post[published_time]"
                                                   value="{:date('Y-m-d H:i:s',$post['published_time'])}" id="published_time" readonly>
                                        </div>
                                    </div>
                                </div>
                                
                                <!-- 详细内容 -->
                                <if condition="in_array('content',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">详细内容</label>
                                    <div class="layui-input-block">
                                        <script  class="form-replace" type="text/plain" id="detail_content" name="post[post_content]">{$post.post_content}</script>
                                    </div>
                                </div>
                                </if>
                           
                              
                                <!-- 上传图片 -->
                                <!-- <if condition="in_array('thumb',$field_list)">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('UPLOAD_IMAGE')}</label>
                                
                                    <div class="layui-input-block">
                                        <div class="upload-image">
                                            <input type="hidden" name="post[more][thumbnail]" id="thumbnail"
                                                   value="{$post.more.thumbnail|default=''}">
                                            <a href="javascript:uploadOneImage('{:lang('UPLOAD_IMAGE')}','#thumbnail');">
                                                <if condition="empty($post.more.thumbnail)">
                                                    <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                                         id="thumbnail-preview"
                                                         width="150"/>
                                                    <else/>
                                                    <img src="{:cmf_get_image_preview_url($post.more.thumbnail)}"
                                                         id="thumbnail-preview"
                                                         width="150"/>
                                                </if>
                                            </a>
                                            <input type="button" class="layui-btn layui-btn-danger layui-btn-sm btn-cancel-thumbnail" value="{:lang('CANCEL_PICTURE')}">
                                        </div>
                                    </div>
                                </div>
                                </if> -->

                                <!-- <notempty name="categories">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">{:lang('PICTURE_RECOMMENDED_SIZE')}</label>
                                        <div class="layui-input-block">
                                            <table class="layui-table thumb-size" style="max-width:500px;" lay-size="sm">
                                                <tr>
                                                    <td>{:lang('CATEGORY')}</td>
                                                    <td>{:lang('IMAGE_SIZE')}</td>
                                                </tr>

                                            <foreach name="categories" item="vo">
                                                <tr>
                                                    <td>{$vo.name}</td>
                                                    <td>{$vo.thumb_size}</td>
                                                </tr>
                                            </foreach>
                                            </table>
                                        </div>
                                    </div>
                                </notempty> -->

                                <!-- 相册 -->
                                <if condition="in_array('album',$field_list)">
                                <!-- <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('ALBUM')}</label>
                                    <div class="layui-input-block">
                                        <ul id="photos" class="pic-list list-unstyled form-inline">
                                            <notempty name="post.more.photos">
                                                <foreach name="post.more.photos" item="vo">
                                                    <php>$img_url=cmf_get_image_preview_url($vo['url']);</php>
                                                    <li id="saved-image{$key}">
                                                        <input id="photo-{$key}" type="hidden" name="photo_urls[]"
                                                               value="{$vo.url}">
                                                        <input class="layui-input" id="photo-{$key}-name" type="text"
                                                               name="photo_names[]"
                                                               value="{$vo.name|default=''}" style="width: 200px;" title="图片名称">
                                                        <img id="photo-{$key}-preview"
                                                             src="{:cmf_get_image_preview_url($vo['url'])}"
                                                             style="height:36px;width: 36px;"
                                                             onclick="parent.imagePreviewDialog(this.src);">
                                                        <a href="javascript:uploadOneImage('图片上传','#photo-{$key}');">{:lang('REPLACE')}</a>
                                                        <a href="javascript:(function(){$('#saved-image{$key}').remove();})();">{:lang('REMOVE')}</a>
                                                    </li>
                                                </foreach>
                                            </notempty>
                                        </ul>
                                        <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                                           class="layui-btn layui-btn-normal">选择图片</a>
                                    </div>
                                </div> -->
                                </if>

                                <!-- 附件 -->
                                <!-- <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('UPLOAD_FILE')}</label>
                                    <div class="layui-input-block">
                                        <ul id="files" class="pic-list list-unstyled form-inline">
                                            <notempty name="post.more.files">
                                                <foreach name="post.more.files" item="vo">
                                                    <php>$file_url=cmf_get_file_download_url($vo['url']);</php>
                                                    <li id="saved-file{$key}">
                                                        <input id="file-{$key}" type="hidden" name="file_urls[]"
                                                               value="{$vo.url}">
                                                        <input class="layui-input" id="file-{$key}-name" type="text"
                                                               name="file_names[]"
                                                               value="{$vo.name}" style="width: 200px;" title="文件名称">
                                                        <a id="file-{$key}-preview" href="{$file_url}" target="_blank">下载</a>
                                                        <a href="javascript:uploadOne('附件上传','#file-{$key}','file');">替换</a>
                                                        <a href="javascript:(function(){$('#saved-file{$key}').remove();})();">移除</a>
                                                    </li>
                                                </foreach>
                                            </notempty>
                                        </ul>
                                        <a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl');"
                                           class="layui-btn layui-btn-normal">选择文件</a>
                                    </div>
                                </div> -->

                                <!-- 排序号 -->
                                <!-- <div class="layui-form-item">
                                    <label class="layui-form-label">{:lang('SORT')}</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" name="post['list_order']" value="{$list_order}">
                                    </div>
                                </div> -->
                                <!-- <notempty name="field_status_list">
                                    <div class="layui-form-item">
                                        <php>
                                            /*$status_yes=$post['post_status']==99?"checked":"";*/
                                            $is_top_yes=$post['is_top']==1?"checked":"";
                                            $recommended_yes=$post['recommended']==1?"checked":"";
                                        </php>
                                        <label class="layui-form-label">{:lang('ATTRIBUTE')}</label>
                                        <div class="layui-input-block">
                                            <div class="checkbox">

                                                <if condition="in_array('status_is_top',$field_list)">
                                                    <input type="checkbox" name="post[is_top]" title="{:lang('IS_TOP')}" value="1" {$is_top_yes}>
                                                </if>

                                                <if condition="in_array('status_recom',$field_list)">
                                                    <input type="checkbox" name="post[recommended]" title="{:lang('RECOMMENDED')}" value="1" {$recommended_yes}>
                                                </if>
                                            </div>
                                        </div>
                                    </div>
                                </notempty> -->

                                <!-- 是否已经领取 -->
                                <div class="layui-form-item">
                                    <php>
                                        $receive_status0 = $post['receive_status']==1 ? "checked" : "";
                                        $receive_status1 = $post['receive_status']==2 ? "checked" : "";
                                    </php>
                                    <label class="layui-form-label">是否领取</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="post[receive_status]" value="1" title="未领取" {$receive_status0} lay-filter="no_receive">
                                        <input type="radio" name="post[receive_status]" value="2" title="已领取" {$receive_status1} lay-filter="yes_receive">
                                    </div>
                                </div>
                                <style type="text/css">
                                    .receive_box{ display: none; }
                                </style>
                                <!-- 领取人 -->

                                <div class="layui-form-item <if condition='$post[receive_status] eq 1'>receive_box</if>">
                                    <label class="layui-form-label">领取人</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" id="receive_person" name="post[receive_person]"
                                               value="{$post['receive_person']}" data-field="receive_person" placeholder="请填写领取人">
                                    </div>
                                </div>

                                <!-- 联系电话 -->
                                <div class="layui-form-item <if condition='$post[receive_status] eq 1'>receive_box</if>">
                                    <label class="layui-form-label">联系电话</label>
                                    <div class="layui-input-block">
                                        <input class="layui-input form-replace" type="text" id="receive_mobile" name="post[receive_mobile]"
                                               value="{$post['receive_mobile']}" data-field="receive_mobile" placeholder="请填写领取人的联系电话">
                                    </div>
                                </div>
                                <!-- 领取时间 -->
                                <div class="layui-form-item <if condition='$post[receive_status] eq 1'>receive_box</if>">
                                    <label class="layui-form-label">领取时间</label>
                                
                                    <div class="layui-input-block">
                                        <input class="layui-input js-layui-datetime" type="text" name="post[receive_time]"
                                               value="{$post['receive_time']}" id="receive_time" readonly>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item padding-left-25">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn layui-btn-normal" onclick="CheckSenSubmit();" id="add-key">{:lang('SAVE')}</button>
                        <button type="submit" class="layui-btn layui-btn-normal js-ajax-submit" style="display:none;" id="js-ajax-submit">{:lang('SAVE')}</button>
                        <!-- <button type="button" class="layui-btn layui-btn-normal content-preview" onclick="contentPreview(editorcontent,'title','published_time');" id="add-key">{:lang('PREVIEW')}</button> -->
                        <a class="layui-btn layui-btn-primary" href="javascript:history.back(-1);">{:lang('BACK')}</a>
                    </div>
                </div>
                    
            </div>
        </form>
    </div>
</div>

<include file="public@footer"/>
<include file="admin@theme/scripts"/>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
    $(function () {
        if( $('#detail_content').length ){
            // $('.content-preview').show();
            UE.getEditor('detail_content');
        }

        if( $('#post_excerpt').length ){
            UE.getEditor('post_excerpt');
        }
        

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

        $('#more-template-select').val("{$post.more.template|default=''}");


    });

    //选择是否领取
    var form = layui.form;
    form.on('radio(no_receive)', function(data){
        $('.receive_box').hide();
    });
    form.on('radio(yes_receive)', function(data){
        $('.receive_box').show();
    });

    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminCategory/select')}?operate=edit&ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>

